-
Notifications
You must be signed in to change notification settings - Fork 413
Allow SWR mutation in useUser hook #2045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2045 +/- ##
==========================================
+ Coverage 78.47% 80.02% +1.55%
==========================================
Files 21 21
Lines 1909 1907 -2
Branches 307 315 +8
==========================================
+ Hits 1498 1526 +28
+ Misses 405 376 -29
+ Partials 6 5 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This has been taken care of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds an invalidate function to the useUser hook to allow clients to manually trigger a SWR revalidation of the user profile. In addition, the PR includes various style and formatting improvements and updates to related tests to ensure full coverage of the new functionality.
- Added an invalidate method to the useUser hook.
- Updated both unit and integration tests to verify the correct behavior of invalidate.
- Made minor formatting and code style adjustments across several session and auth client files.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/server/session/stateless-session-store.ts | Refactored import and formatting of cookie decryption and cookie deletion. |
src/server/session/stateless-session-store.test.ts | Updated cookie name quoting and test formatting for clarity. |
src/server/session/stateful-session-store.test.ts | Cleaned up extra whitespace and standardized argument ordering. |
src/server/cookies.ts | Simplified arrow function syntax while preserving functionality. |
src/server/auth-client.ts | Reordered some error imports and formatted promise return type declarations. |
src/server/auth-client.test.ts | Adjusted bracket notation for property access and test callback formatting. |
src/client/hooks/use-user.unit.test.tsx | Added unit tests to cover the new invalidate functionality and revised SWR mocks. |
src/client/hooks/use-user.ts | Extended useUser to include invalidate using mutate and re-ordered error/data checks. |
src/client/hooks/use-user.integration.test.tsx | Introduced integration tests to validate re-fetch behavior and error handling on invalidate. |
// Call invalidate to trigger re-fetch | ||
await act(async () => { | ||
result.current.invalidate(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user calls invalidate, it is going to call the URL again, is that correct? If yes, what is the reasoning for naming this invalidate
, rather than refresh
or so ?
Fixes: #1937
Changes
invalidate
function to the return value of theuseUser
hook./auth/profile
endpoint.Testing
Tests have been updated in
src/client/hooks/use-user.test.tsx
to cover the newinvalidate
functionality, ensuring it correctly triggers a data refresh using SWR'smutate
function.PASSING
Usage
Client Components:
You can access the
invalidate
function from theuseUser
hook and call it when you need to refresh the user data, for example, after a user profile update action.